cmake_minimum_required(VERSION 3.5)

project(ninstaller VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets LinguistTools)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets LinguistTools Core DBus)
find_package(yaml-cpp REQUIRED)


set(TS_FILES ninstaller_zh_CN.ts)

include_directories(
    ${Qt5Core_INCLUDE_DIRS}
    ${CMAKE_CURRENT_SOURCE_DIR}
)

set(PROJECT_SOURCES
        main.cpp
        base.h
        base.cpp
        mainwindow.cpp
        mainwindow.h
        mainwindow.ui
        chooselanguage.cpp chooselanguage.h chooselanguage.ui
        checkiso.cpp checkiso.h checkiso.ui
        choosezone.h choosezone.cpp choosezone.ui
        createuser.h createuser.cpp createuser.ui
        partitiondisk.h partitiondisk.cpp partitiondisk.ui
        install.h install.cpp install.ui
        finish.h finish.cpp finish.ui
        agreementdialog.cpp agreementdialog.h agreementdialog.ui
        rebootui.h rebootui.cpp rebootui.ui
        timezonewidget.h timezonewidget.cpp


        locale/TimeZone.h
        locale/TimeZone.cpp
        locale/TimeZoneImage.h
        locale/TimeZoneImage.cpp
        locale/TranslatableString.h
        locale/TranslatableString.cpp
        locale/String.h
        locale/String.cpp
        locale/DllMacro.h
        locale/Config.h
        locale/Config.cpp
        locale/LocaleConfiguration.h
        locale/LocaleConfiguration.cpp
        locale/Job.h
        locale/Job.cpp
        locale/SetTimezoneJob.h
        locale/SetTimezoneJob.cpp
        locale/GlobalStorage.h
        locale/GlobalStorage.cpp
        locale/JobQueue.h
        locale/JobQueue.cpp
        locale/Settings.h
        locale/Settings.cpp
        locale/Actions.h
        locale/InstanceKey.h
        locale/InstanceKey.cpp
        locale/Runner.h
        locale/Runner.cpp
        locale/CalamaresUtilsSystem.h
        locale/CalamaresUtilsSystem.cpp
        locale/Units.h
        locale/Yaml.h
        locale/Yaml.cpp
        locale/Global.h
        locale/Global.cpp
        locale/Translation.h
        locale/Translation.cpp
        locale/Variant.h
        locale/Variant.cpp
        locale/LocaleNames.h
        locale/LocaleNames.cpp
        locale/Dirs.h
        locale/Dirs.cpp
        locale/CalamaresConfig.h

        common.h
        ${TS_FILES}
)

# 添加资源文件
set(RESOURCE_FILES "${CMAKE_SOURCE_DIR}/resource/res.qrc" "${CMAKE_SOURCE_DIR}/resource/locale.qrc")
qt_add_resources(QRC_RESOURCES ${RESOURCE_FILES})

add_executable(ninstaller
    ${PROJECT_SOURCES}
    ${QRC_RESOURCES}
)

qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})

target_link_libraries(ninstaller PRIVATE
    Qt${QT_VERSION_MAJOR}::Widgets
    Qt5::Core
    Qt5::DBus
    yaml-cpp
)

set_target_properties(ninstaller PROPERTIES
    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

install(TARGETS ninstaller
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

install(FILES "ninstaller.desktop"
    DESTINATION "/usr/share/applications/")
install(FILES "resource/icons/icon_installer_16.png"
    DESTINATION "/usr/share/icons/hicolor/16x16/apps/"
    RENAME "ninstaller.png"
)
install(FILES "resource/icons/icon_installer_22.png"
    DESTINATION "/usr/share/icons/hicolor/22x22/apps/"
    RENAME "ninstaller.png"
)
install(FILES "resource/icons/icon_installer_24.png"
    DESTINATION "/usr/share/icons/hicolor/24x24/apps/"
    RENAME "ninstaller.png"
)
install(FILES "resource/icons/icon_installer_32.png"
    DESTINATION "/usr/share/icons/hicolor/32x32/apps/"
    RENAME "ninstaller.png"
)
install(FILES "resource/icons/icon_installer_48.png"
    DESTINATION "/usr/share/icons/hicolor/48x48/apps/"
    RENAME "ninstaller.png"
)
install(FILES "resource/icons/icon_installer_48.svg"
    DESTINATION "/usr/share/icons/hicolor/scalable/apps/"
    RENAME "ninstaller.svg"
)

install(FILES "misc/99-allow-timezone.rules"
    DESTINATION "/etc/polkit-1/rules.d/99-allow-timezone.rules")


